# Copyright (c) 2008 Alvin Wang http://cloudwizard.com/
# License New BSD
# See README for additional information

"""SliceHost Cloud Support"""

from cloudwizard.cloud import Cloud
from cloudwizard.compute import ComputeService
from cloudwizard.compute import ComputeDevice
from cloudwizard.config import Config
from cloudwizard.ssh import Connection
from pyactiveresource.activeresource import ActiveResource


class Slicehost(Cloud):
    """
    aws_access_key_id = None
    aws_secret_access_key = None
    aws_key_pair = 'testa'
    ec2_conn = None	#?? how to encapsulate
    cloud_vartypes = ['aws_ami', 'aws_keypair', 'aws_secgroup', 'aws_ipaddr',
          'aws_disk']
    """
    cloud_name = "SliceHost"
    cloud_abbrev = "slicehost"

    def script_auth(self):
        self.cloud_auth = Config( cloud_abbrev=self.cloud_abbrev, type='user',
            autoload=False) 
    
        self.cloud_auth.prompt(question="What is your API password?", varname="api_password")
        username = self.cloud_auth.prompt(question="What user name would you like to save this under?",
            default='default', varname="username")
        self.cloud_auth.write_config( config_name=username)

    def script_server(self):
        self.cloud_auth = Config( cloud_abbrev=self.cloud_abbrev, type='system',
            autoload=False)     
        self.cloud_auth.prompt(question="What is your API password?", varname="api_password")
        self.cloud_auth.prompt(question="What is your IP address?", varname="ip")
        self.cloud_auth.prompt(question="What is your user?", varname="user", default="root")
        self.cloud_auth.prompt(question="What is your password?", varname="password")
        servername = self.cloud_auth.prompt(question="What server name would you like to save this under?",
            default='default', varname="servername")
        self.cloud_auth.write_config( config_name=servername)


    def get_service(self, service=None, **args):
        """return a AWS service"""
        # could use lambda but it is more painful
        if service == "compute":
          return Compute(aws_access_id=self.cloud_userid,
            aws_secret_key=self.cloud_password)
        if service == "ec2":
          return Ec2(aws_access_id=self.cloud_userid,
            aws_secret_key=self.cloud_password,
            config_path=self.config_path)
        if service == "sqs":
          return Sqs(aws_access_id=self.cloud_userid,
            aws_secret_key=self.cloud_password)
        # error?

